<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>简易计算器</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javaScript">
   function operater(){  
	   var num1Vaule = document.form1.num1.value;
	   var num2Value=document.form1.num2.value;
        if(num1Vaule=="" || num2Value == ""){  
           alert("参与计算的操作数的数值不能为空 ！！");  
           return false;  
        }  
        //判断num1是不是一个数  
        if(isNaN(num1Vaule)){  
          alert("第一个数不是数值型数据，请确认！")  
           return false;  
        }  
        if(isNaN(num2Value)){  
          alert("第二个数不是数值型数据，请确认！");  
          return false;  
        }  
        var operValue = document.form1.oper.value;
        var resultValue = 0;
        if(operValue=="0"){
        	resultValue = parseFloat(num1Vaule)+parseFloat(num2Value);
        }
        if(operValue=="1"){
        	resultValue = parseFloat(num1Vaule)-parseFloat(num2Value);
        }
        if(operValue=="2"){
        	resultValue = parseFloat(num1Vaule)*parseFloat(num2Value);
        }
        if(operValue=="3"){
        	resultValue = parseFloat(num1Vaule)/parseFloat(num2Value);
        }
          document.form1.result.value= resultValue;
      }  
    
    </script>
  </head>
  
  <body>
      <form name="form1" action="">
           <h1>我的计算器</h1>
           <hr size="2"/>
           <p>请输入第一个数：<input type="text" name="num1"></p>
           <p>请选择运算方式：
             <select name="oper">  
	             <option value="0">+</option>  
	             <option value="1">-</option>  
	             <option value="2">*</option>   
	             <option value="3">/</option>  
            </select>
           </p>
           <p>请输入第二个数：<input type="text" name="num2"></p>
           <input type="button" value="计算" onclick="operater()"/>&nbsp;&nbsp;
           <input type="reset" value="重置" />&nbsp;&nbsp;
            <p>结果：<input type="text" name="result"></p>
      </form>
  </body>
</html>
